using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Pub_Module_J_News1 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
    }
    public string LimitWord(string value)
    {
        //String html = "Whatever your html is";
        //html = Regex.Replace(html, @"</?[^>]*>", ""); 
        value = StripHtml(value, false);

        int length = 400;
        if (value.Length > length)
            return "&nbsp;&nbsp;" + value.Substring(0, length) + "...";
        else
            return "&nbsp;&nbsp;" + value;

    }

    public static string StripHtml(string html, bool allowHarmlessTags)
    {
        if (html == null || html == string.Empty)
            return string.Empty;

        if (allowHarmlessTags)
            return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty);

        return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);
    }


    private void BindData()
    {
        string viewcount = System.Configuration.ConfigurationManager.AppSettings["TopNews"];
        string KindNo = "N";
        if (Request.QueryString["KindNo"] != "" && Request.QueryString["KindNo"] != null)
            KindNo = Request.QueryString["KindNo"];
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("NewsID", "0");
        msg.CreateFirstNode("Title", "");
        msg.CreateFirstNode("KindNo", cls.killSQLInjection(KindNo));
        msg.CreateFirstNode("Status", "");
        msg.CreateFirstNode("ViewCount", viewcount);

        DataTable dt = null;
        dt = cls.Get_NewsByCondition(msg.GetXmlStr).Tables[0];


        if (dt.Rows.Count > 0)
        {
            string HTML = "<div id='featured_News'>";
            HTML += "<ul class='ui-tabs-nav'>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                HTML += "<li class='ui-tabs-nav-item'  id='nav-fragment-" + i + "'><a href='#featured_News-" + i + "'><img width='50px' height='50px' src='" + ResolveUrl("~/") + dt.Rows[i]["ImgUrl"].ToString() + "'><span>" + dt.Rows[i]["Title"].ToString() + "</span></a></li>";
            }
            HTML += "</ul>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                HTML += "<div id='featured_News-" + i + "' class='ui-tabs-panel' style=''>";
                HTML += "<img src='" + ResolveUrl("~/") + dt.Rows[i]["ImgUrl"].ToString() + "' alt='' width='175px' height='190px'  />";
                HTML += "<div class='info'>";
                HTML += " <h3><a href='#'>" + dt.Rows[i]["Title"].ToString() + "</a></h3>";
                HTML += "<p>";
                HTML += "<a href='" + ResolveUrl("~/") + "Shopping/Stall/ProductDetail.aspx?PDID=" + dt.Rows[i]["NewsID"].ToString() + "'>" + LimitWord(dt.Rows[i]["Content"].ToString()) + "</a>";
                HTML += "</p>";
                HTML += "  </div>";
                HTML += "</div>";

            }
            HTML += "</div>";
            ltrMaster.Text = HTML;
        }
    }
}
